const EventEmitter = require('events');

const emitter1 = new EventEmitter();

//绑定事件
emitter1.on('a1', function(x, y) {
	console.log(x, y, this == emitter1);//11, 12,true
});

emitter1.on('a1', (x, y) => {
	//使用箭头函数,this不再指向 emitter1
	console.log(x, y, this);//11, 12,{}
});

emitter1.emit('a1', 11, 12);

emitter1.once('a2', (x, y) => {
	console.log(x, y, this);//11, 12,{}
});
console.log(emitter1.eventNames());//['a1', 'a2']
console.log(emitter1.listenerCount('a1'));//2
console.log(emitter1.listeners('a1'));//[fn,fn]